{% block sw_settings_rule_detail_base %}
<div class="sw-settings-rule-detail-base">
    {% block sw_settings_rule_detail_base_content_card %}
    <mt-card
        position-identifier="sw-settings-rule-detail-base-content"
        :large="true"
        :is-loading="isLoading"
        :title="$tc('sw-settings-rule.detail.titleCard')"
    >
        <template v-if="rule">
            <div style="display: grid; grid-template-columns: 2fr 1fr; grid-column-gap: 32px">
                {% block sw_settings_rule_detail_base_content_card_field_name %}

                <mt-text-field
                    v-model="rule.name"
                    name="sw-field--rule-name"
                    :label="$tc('sw-settings-rule.detail.labelName')"
                    :placeholder="$tc('sw-settings-rule.detail.placeholderName')"
                    :error="ruleNameError"
                    :disabled="!acl.can('rule.editor') || undefined"
                    required
                />
                {% endblock %}

                {% block sw_settings_rule_detail_base_content_card_field_priority %}
                <mt-number-field
                    v-model="rule.priority"
                    name="sw-field--rule-priority"
                    :label="$tc('sw-settings-rule.detail.labelPriority')"
                    :placeholder="$tc('sw-settings-rule.detail.placeholderPriority')"
                    :error="rulePriorityError"
                    :disabled="!acl.can('rule.editor') || undefined"
                    :step="1"
                    :min="0"
                    number-type="int"
                    required
                />
                {% endblock %}
            </div>

            {% block sw_settings_rule_detail_base_content_card_field_description %}
            <mt-textarea
                v-model="rule.description"
                name="sw-field--rule-description"
                :label="$tc('sw-settings-rule.detail.labelDescription')"
                :placeholder="$tc('sw-settings-rule.detail.placeholderDescription')"
                :disabled="!acl.can('rule.editor') || undefined"
            />
            {% endblock %}

            <div style="display: grid; grid-template-columns: 1fr 1fr; grid-column-gap: 32px">
                {% block sw_settings_rule_detail_base_content_card_field_type %}
                <sw-multi-select
                    v-if="rule"
                    v-model:value="moduleTypes"
                    name="sw-field--moduleTypes"
                    class="sw-settings-rule-detail__type-field"
                    value-property="id"
                    label-property="name"
                    :label="$tc('sw-settings-rule.detail.labelType')"
                    :disabled="!acl.can('rule.editor') || undefined"
                    :options="availableModuleTypes"
                >
                    <template #selection-label-property="{ item }">
                        {{ $tc(item.name) }}
                    </template>

                    <template #result-label-property="{ item }">
                        {{ $tc(item.name) }}
                    </template>
                </sw-multi-select>
                {% endblock %}

                {% block sw_settings_rule_detail_base_content_card_field_tags %}
                <sw-entity-tag-select
                    v-if="rule"
                    v-model:entity-collection="rule.tags"
                    name="sw-field--rule-tags"
                    class="sw-settings-rule-detail__tags-field"
                    :label="$tc('global.sw-tag-field.title')"
                    :disabled="!acl.can('rule.editor') || undefined"
                    :placeholder="$tc('sw-settings-rule.detail.placeholderTags')"
                />
                {% endblock %}
            </div>
        </template>
        <sw-loader v-else />
    </mt-card>
    {% endblock %}

    {% block sw_settings_rule_detail_base_conditions_card %}
    <mt-card
        class="sw-settings-rule-detail__condition_container"
        position-identifier="sw-settings-rule-detail-base-conditions"
        :large="true"
        :is-loading="isLoading"
        :title="$tc('sw-settings-rule.detail.ruleCard')"
    >
        <template #headerRight>
            <sw-extension-teaser-popover
                position-identifier="sw-settings-rule-preview-mode-switch"
            />
        </template>

        <sw-condition-tree
            :initial-conditions="conditions"
            :condition-repository="conditionRepository"
            :condition-data-provider-service="ruleConditionDataProviderService"
            association-field="ruleId"
            :association-value="rule.id"
            :association-entity="rule"
            :root-condition="null"
            :disabled="!acl.can('rule.editor') || undefined"
            @conditions-changed="$emit('conditions-changed', $event)"
            @initial-loading-done="$emit('tree-finished-loading')"
        />
    </mt-card>
    {% endblock %}

    {% block sw_settings_rule_detail_custom_field_sets %}
    <mt-card
        v-if="showCustomFields"
        position-identifier="sw-settings-rule-detail-base-custom-field-sets"
        :large="true"
        :title="$tc('sw-settings-custom-field.general.mainMenuItemGeneral')"
        :is-loading="isLoading"
    >
        <sw-custom-field-set-renderer
            :entity="rule"
            :disabled="!acl.can('rule.editor') || undefined"
            :sets="customFieldSets"
        />
    </mt-card>
    {% endblock %}
</div>
{% endblock %}
